package com.settlement.system.converter;


import com.alibaba.excel.converters.integer.IntegerStringConverter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.CellData;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.settlement.system.common.enums.WpTypeEnum;
import org.apache.commons.lang3.StringUtils;

import java.text.ParseException;

/**
 * @author author
 */
public class WpOrderTypeConvert extends IntegerStringConverter {

    @Override
    public WriteCellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        if(value != null){
            WpTypeEnum.ORDER_TYPE[] orderTypes = WpTypeEnum.ORDER_TYPE.values();
            for(int index = 0;index < orderTypes.length;index++){
                if(orderTypes[index].getNo().equals(value)){
                    return new WriteCellData(orderTypes[index].getName());
                }
            }
        }
        return new WriteCellData();
    }

    @Override
    public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException {
        String value = cellData.getStringValue();
        if(!StringUtils.isEmpty(value)){
            WpTypeEnum.ORDER_TYPE[] orderTypes = WpTypeEnum.ORDER_TYPE.values();
            for(int index = 0;index < orderTypes.length;index++){
                if(orderTypes[index].getName().equals(value)){
                    return orderTypes[index].getNo();
                }
            }
        }
        return null;
    }
}
